package holdObject;

import java.util.ArrayList;
class GrannySmith extends Apple{}
class Gala extends Apple{}
class Fuji extends Apple{}
class Braeburn extends Apple{}

public class GenericsAndUpcasting {
	public static void main(String[] args){
		ArrayList<Apple> apples = new ArrayList<>();
		/*
		 * 加进去的时候相当于执行了向上转型
		 */
		apples.add(new GrannySmith());
		apples.add(new Gala());
		apples.add(new Fuji());
		apples.add(new Braeburn());
		/*
		 * 相当于调用了get（），也就是相当于自动执行了向下转型
		 */
		for (Apple apple:apples) {
			System.out.println(apple);
		}
	}
}
